package com.expand03;

import java.lang.reflect.Constructor;

/**
 * Created by yangjun on 2018/3/23.
 */
public class SingletonFactory {
    public static Singleton singleton;

    static {
        try {
            Class cl = Class.forName(Singleton.class.getName());
            //获取无参构造器
            Constructor constructor = cl.getDeclaredConstructor();
            //设置私有无参构造器可以访问
            constructor.setAccessible(true);
            //产生一个实例
            singleton = (Singleton) constructor.newInstance();
        } catch (Exception e) {
            //异常处理
        }
    }

    public static Singleton getSingleton() {
        return singleton;
    }
}
